from datetime import datetime
from django.contrib import admin
from django.utils.html import format_html

from account.models import Account

# Register your models here.
@admin.register(Account)
class AccountAdmin(admin.ModelAdmin):
    list_display = ['pk', 'get_avatar', 'nickname', 'remark', 'create_time']

    search_fields = ['nickname', 'wx_openid','remark']

    fieldsets = [
        (
            None,
            {
                "fields": ["avatar", "nickname"],
            },
        ),
        (
            "额外选项",
            {
                "classes": ["collapse"],
                "fields": ["remark", "enable"],
            },
        ),
    ]

    def get_avatar(self, obj):
        if obj.avatar:
            return format_html(
                '<img src="{}" width="100"/>',
                obj.avatar.url
            )
        return ''
    get_avatar.short_description = '头像'